package com.ext.aic.config;

import android.content.Context;

import androidx.lifecycle.LifecycleOwner;

import com.ext.aic.apis.agent.IntervalRequest;
import com.eyinfo.mpkv.MPLocalKV;

public class BoxConfig {
    private static volatile BoxConfig instance;

    public static BoxConfig getInstance() {
        if (instance == null) {
            synchronized (BoxConfig.class) {
                if (instance == null) {
                    instance = new BoxConfig();
                }
            }
        }
        return instance;
    }

    private String replyIntervalTimeKey = "95349cbaf57dddec";

    public void config(Context context, LifecycleOwner lifecycleOwner) {
        intervalRequest.request(context, lifecycleOwner);
    }

    private IntervalRequest intervalRequest = new IntervalRequest() {
        @Override
        protected void onIntervalSuccess(int interval) {
            MPLocalKV.getInstance().put(replyIntervalTimeKey, interval * 1000);
        }
    };

    //获取回复间隔时间(毫秒)
    public int getReplyIntervalTime() {
        //默认回复间隔时间
        return MPLocalKV.getInstance().getInt(replyIntervalTimeKey, 5000);
    }
}
